---
title:  JCA Resource Adapter Example
---

<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

This example shows how to use the JCA Resource Adapter in Geode .

``` pre
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, “weblogic.jndi.WLInitialContextFactory”);
env.put(Context.PROVIDER_URL, “t3://localhost:7001”);
Context ctx = new InitialContext(env);
UserTransaction utx = (UserTransaction) ctx.lookup(“javax.transaction.UserTransaction”);
utx.begin();
      // the XA Resource
javax.sql.DataSource ds = (DataSource) ctx.lookup(“derby”);
javax.sql.Connection derbyConn = ds.getConnection();
Statement stmt = conn.createStatement();
stmt.executeUpdate(“insert into test values(2,4) “);
     // do ConnectionFactory lookup
GFConnectionFactory cf = (GFConnectionFactory) ctx.lookup(“gfe/jca”);

     // Obtaining the connection begins the LocalTransaction.
     // If this is absent, operations will not be part of any transaction.
GFConnection conn = cf.getConnection();

testRegion.put(“foo”, “bar-”);
utx.commit();

     // the connection can also be closed within the transaction
derbyConn.close();
conn.close();
```


